﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using WenABP.Customer.Application;
using WenABP.Customer.EntityFrameworkCore;

namespace WenABP.Customer.API
{
    [DependsOn(typeof(WenABPCustomerApplicationModule),
        typeof(AbpAspNetCoreMvcModule),
        typeof(AbpAutofacModule),
        typeof(WenABPCustomerEFCoreModule))]
    public class WenABPCustomerAPIModule:AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            Configure<AbpAspNetCoreMvcOptions>(options=> 
            {
                options.ConventionalControllers.Create(typeof(WenABPCustomerApplicationModule).Assembly);
            });
            ConfigureSwaggerServices(context.Services);
        }


        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var env = context.GetEnvironment();

            app.UseRouting();
            app.UseConfiguredEndpoints();

            app.UseSwagger();
            app.UseSwaggerUI(options=> 
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json","WenCustomer API");
            });
        }

        private void ConfigureSwaggerServices(IServiceCollection services)
        {
            services.AddSwaggerGen(options=> 
            {
                options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Wen Customer API", Version = "v0.1" });
                options.DocInclusionPredicate((docName,description)=>true);
                options.CustomSchemaIds(type=>type.FullName);
            });
        }
    }
}
